package com.oocl.euc.core.builder;

import com.oocl.euc.core.attachment.model.Attachment;
import com.oocl.euc.core.attachment.repository.AttachmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AttachmentBuilder {

    private Attachment attachment;

    @Autowired
    private AttachmentRepository attachmentRepository;

    public AttachmentBuilder defaultBuilder() {
        this.attachment = new Attachment();
        this.attachment.setLength(100L);
        this.attachment.setContentType("multipart/form-data");
        return this;
    }

    public AttachmentBuilder withMd5Code(String md5Code){
        attachment.setMd5Code(md5Code);
        return this;
    }

    public AttachmentBuilder withFileName(String fileName){
        attachment.setFileName(fileName);
        return this;
    }

    public AttachmentBuilder withContent(byte[] content){
        attachment.setContent(content);
        return this;
    }

    public AttachmentBuilder withContentType(String contentType){
        attachment.setContentType(contentType);
        return this;
    }

    public AttachmentBuilder withLength(Long length){
        attachment.setLength(length);
        return this;
    }

    public Attachment create(){
        return attachment;
    }

    public Attachment saveToDB(){
        attachmentRepository.save(attachment);
        return attachment;
    }
}
